--require "MainScene"

JLSJBuyPointLayer={}
JLSJBuyPointLayerFunc={}
JLSJBuyPointLayerFunc.__index = JLSJBuyPointLayerFunc
setmetatable(JLSJBuyPointLayer, JLSJBuyPointLayerFunc)

JLSJBuyPointLayerFunc.getNode = function(self)
  local l = {}
  setmetatable(l, JLSJBuyPointLayerFunc)
  l.node = CCBReader:load("JunXiaoScene3.ccbi")
  print("JLSJBuyPointLayer.getNode", JLSJBuyPointLayer.node)
  l:init() 
  return l 
end

JLSJBuyPointLayerFunc.getScene = function(self)
  local sc = CCScene:create()
  sc:addChild(JLSJBuyPointLayer:getNode().node)  
  print("JLSJBuyPointLayer.getScene", sc)
  return sc
end

JLSJBuyPointLayerFunc.init = function(self)
  --self:initTable()
  setObjectExtTable(self.node:getChildByTag(1020), self)
  setObjectExtTable(self.node:getChildByTag(1021), self)
  setObjectExtTable(self.node:getChildByTag(1024), self)
  setObjectExtTable(self.node:getChildByTag(1111), self)
 
  local bl = TypeCast(self.node:getChildByTag(1020), "CCButton")
  local br = TypeCast(self.node:getChildByTag(1021), "CCButton")
  self.uiStepper = UIStepper:create(bl, br, "onUIStepperChanged", self)
  self.uiStepper:setCount(10)
  self.uiStepper:setIndex(0)
end
JLSJBuyPointLayerFunc.onUIStepperChanged = function(self, index)
  TypeCast(self.node:getChildByTag(1012), "CCLabelTTF"):setString(tostring(index+1))
  TypeCast(self.node:getChildByTag(1013), "CCLabelTTF"):setString(string.format("总价: %d军饷", (index+1)*2))
end
JLSJBuyPointLayerFunc.onBuyButton = function(self, node, event)
  NetworkRequest.buyItem(30, self.uiStepper.index+1, "onBuyComplete", self)
  LoadScene:showLoadingScene()
end
JLSJBuyPointLayerFunc.onBuyComplete = function(self, data)
  LoadScene:removeLoadingScene()
  local res = cjson.decode(data)
  if res.ret==0 then
    NetworkRequest.syncData(res)
    self:onCloseButton()
  else
    showMessage(res.msg, ccc3(255,255,0))
  end
end
JLSJBuyPointLayerFunc.onCloseButton = function(self, node, event)
  MainScene.scene:removeChild(self.node, true)
  MainScene.scene:addChild(JLSJLayer:getNode(JLSJLayer.oldGid).node)
end
